package com.ems.service.impl;

import com.ems.entity.TEmp;
import com.ems.mapper.TEmpMapper;
import com.ems.service.ITEmpService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZZH
 * @since 2022-06-27
 */
@Service
public class TEmpServiceImpl extends ServiceImpl<TEmpMapper, TEmp> implements ITEmpService {
    @Autowired
    TEmpMapper tEmpMapper;
    @Override
    public int addEmp(TEmp tEmp) {
        return tEmpMapper.insert(tEmp);
    }

    @Override
    public int deleteEmp(Integer id) {
        return tEmpMapper.deleteById(id);
    }

    @Override
    public int updateEmp(TEmp tEmp) {
        return tEmpMapper.updateById(tEmp);
    }

    @Override
    public List<TEmp> getListEmp() {
        return tEmpMapper.selectList(null);
    }

    @Override
    public double effective() {
        int countWork = tEmpMapper.countWork();
        int countNowork = tEmpMapper.countNoWork();
       double ans = countWork * 1.0/(countNowork + countWork);
        String format = String.format("%.2f", ans);
        ans = Double.valueOf(format);
        return ans;
    }

    @Override
    public List<TEmp> selectBynum(String name)
    {
        return tEmpMapper.selectBynumOrName(name);
    }

    @Override
    public TEmp selectByCode(Integer code) {
        return tEmpMapper.selectByCode(code);
    }

    @Override
    public HashMap<String, Integer> kindNumEmp() {
        HashMap<String,Integer> result = new HashMap<>();
        int freeNum = tEmpMapper.countFree();
        int workNum = tEmpMapper.countWork();
        int leaveNum = tEmpMapper.leaveEmp();
        int quitNum = tEmpMapper.quitWork();
        result.put("空闲人数",freeNum);
        result.put("工作中人数",workNum);
        result.put("请假人数",leaveNum);
        result.put("离职人数",quitNum);
        return result;
    }
}
